using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace WindowsGame2
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        Texture2D megaman;
        Vector2 position;
        Boolean voltando;
        int speed;
        KeyboardState oldKeyboardState;
        KeyboardState currentKeyboardState;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            graphics.PreferredBackBufferWidth = 800;
            graphics.PreferredBackBufferHeight = 400;
            //graphics.IsFullScreen = true;
        }

        protected override void Initialize()
        {
           
           
            position = new Vector2(200f,300f);
            voltando = false;
            speed = 3;


            base.Initialize();
        }

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            megaman = Content.Load<Texture2D>("img/megaman");

        }

        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();
            if (position.X >= graphics.PreferredBackBufferWidth - megaman.Width)
                position.X = graphics.PreferredBackBufferWidth - megaman.Width;
            if (position.X <= 0)
                position.X = 0;
            if (position.Y >= graphics.PreferredBackBufferHeight - megaman.Height)
                position.Y = graphics.PreferredBackBufferHeight - megaman.Height;
            if (position.Y <= 0)
                position.Y = 0;

            oldKeyboardState = currentKeyboardState;
            currentKeyboardState = Keyboard.GetState();

            if (currentKeyboardState.IsKeyDown(Keys.Left))
            {
                position.X -= speed;
            }
            if (currentKeyboardState.IsKeyDown(Keys.Right))
            {
                position.X += speed;
            }
            if (currentKeyboardState.IsKeyDown(Keys.Up))
            {
                position.Y -= speed;
            }
            if (currentKeyboardState.IsKeyDown(Keys.Down))
            {
                position.Y += speed;
            }





            base.Update(gameTime);
        }
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);
            spriteBatch.Begin();
            spriteBatch.Draw(megaman,position,Color.White);
            spriteBatch.End();

            base.Draw(gameTime);
        }
    }
}
